using System;
using System.Collections.Generic;
using System.Linq;
namespace TTSoft.MyApp.Repositories
{
	#region using
	using TTSoft.MyApp.Models;
	#endregion
	public class PhieuPhatRepository
	{
		public static List<PhieuPhat> SelectAll()
		{
			return DataContext.Instance.PhieuPhat.ToList();
		}

		public static PhieuPhat SelectByID(int idphieuphat)
		{
			return DataContext.Instance.PhieuPhat.FirstOrDefault(item => item.IDPhieuPhat == idphieuphat );
		}

		public static bool Insert(PhieuPhat obj)
		{
			try
			{
				DataContext.Instance.PhieuPhat.AddObject(obj);
				DataContext.Instance.SaveChanges();
				return true;
			}
			catch
			{
				return false;
			}
		}

		public static bool Delete(int idphieuphat)
		{
			try
			{
				var delitem = DataContext.Instance.PhieuPhat.FirstOrDefault(item => item.IDPhieuPhat == idphieuphat );
				DataContext.Instance.PhieuPhat.DeleteObject(delitem);
				DataContext.Instance.SaveChanges();
				return true;
			}
			catch
			{
				return false;
			}
		}

		public static bool Save()
		{
			try
			{
				DataContext.Instance.SaveChanges();
				return true;
			}
			catch
			{
				return false;
			}
		}

		public static List<PhieuPhat> RetrieveByID(int idphieuphat)
		{
			return (from item in DataContext.Instance.PhieuPhat where  item.IDPhieuPhat == idphieuphat  select item).ToList();
		}

		public static List<PhieuPhat> SelectByIDDocGia(int iddocgia)
		{
			var lstItem = (from item in DataContext.Instance.PhieuPhat where item.IDDocGia == iddocgia select item).ToList();
			return lstItem;
		}

		public static List<PhieuPhat> SelectByIDLyDo(int idlydo)
		{
			var lstItem = (from item in DataContext.Instance.PhieuPhat where item.IDLyDo == idlydo select item).ToList();
			return lstItem;
		}

	}
}